package com.myself.ssoserver.entity

import com.myself.common.entity.BaseEntity
import com.myself.common.table.BaseTable
import com.myself.ssoserver.entity.LoginHistories.bindTo
import com.myself.ssoserver.entity.Users.references
import org.ktorm.database.Database
import org.ktorm.entity.Entity
import org.ktorm.entity.sequenceOf
import org.ktorm.schema.decimal
import org.ktorm.schema.int
import org.ktorm.schema.varchar
import java.math.BigDecimal

interface TriVersion : BaseEntity<TriVersion> {
    var normal1: Int
    var normal2: Int
    var normal3: Int
    var normal4: Int
    var normal5: Int
    var normal6: Int
    var special: Int
    var status: String
    companion object : Entity.Factory<TriVersion>()
}

interface TriLottery : BaseEntity<TriLottery> {
    var pick1: Int
    var pick2: Int
    var pick3: Int
    var pick4: Int
    var pick5: Int
    var pick6: Int
    var pickSpecial: Int
    var money: BigDecimal
    var realMoney: BigDecimal
    var userId: Int
    var version: TriVersion
    var comment: String
    companion object : Entity.Factory<TriLottery>()
}

object TriVersions : BaseTable<TriVersion>("tri_version") {
    val normal1 = int("normal1").bindTo { it.normal1 }
    val normal2 = int("normal2").bindTo { it.normal2 }
    val normal3 = int("normal3").bindTo { it.normal3 }
    val normal4 = int("normal4").bindTo { it.normal4 }
    val normal5 = int("normal5").bindTo { it.normal5 }
    val normal6 = int("normal6").bindTo { it.normal6 }
    val special = int("special").bindTo { it.special }
    val status = varchar("status").bindTo { it.status }
    val Database.triVersions get() = this.sequenceOf(TriVersions)
}

object TriLotteries : BaseTable<TriLottery>("tri_lottery") {
    val pick1 = int("pick1").bindTo { it.pick1 }
    val pick2 = int("pick2").bindTo { it.pick2 }
    val pick3 = int("pick3").bindTo { it.pick3 }
    val pick4 = int("pick4").bindTo { it.pick4 }
    val pick5 = int("pick5").bindTo { it.pick5 }
    val pick6 = int("pick6").bindTo { it.pick6 }
    val pickSpecial = int("pick_special").bindTo { it.pickSpecial }
    val money = decimal("money").bindTo { it.money }
    val userId = int("user_id").bindTo { it.userId }
    val versionId = int("version_id").references(TriVersions) { it.version }
    val comment = varchar("comment").bindTo { it.comment }
    val realMoney= decimal("real_money").bindTo { it.realMoney }
    val Database.triLotteries get() = this.sequenceOf(TriLotteries)
}
